package com.penglecode.netty.codec.protostuff;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;

import com.penglecode.protostuff.runtime.ObjectSerializer;

public class ProtostuffObjectDecoder extends OneToOneDecoder {

	private ObjectSerializer serializer;
	
	public ProtostuffObjectDecoder(ObjectSerializer serializer) {
		super();
		this.serializer = serializer;
	}
	
	protected Object decode(ChannelHandlerContext ctx, Channel channel,
			Object msg) throws Exception {
		ChannelBuffer buffer = (ChannelBuffer)msg;
		Object object = serializer.deserialize(buffer.array());
		return object;
	}

}
